package com.testproject.imageloadertest;

import java.util.ArrayList;

import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListCurveDisplay extends BaseAdapter {

	private ArrayList<String> arrList;
	private LayoutInflater layoutInflater = null;
	private Activity activity;

	private ImageLoader loader =null;
	public CustomListCurveDisplay(Activity activity, ArrayList<String> arrlist) {
		this.activity = activity;
		this.arrList = arrlist;
		
		loader = new ImageLoader(this.activity);
		
		this.layoutInflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public static class ViewHolder {		
		public ImageView imgProperty;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return this.arrList.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.arrList.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		final ViewHolder holder;

		if (convertView == null) {
			vi = this.layoutInflater.inflate(R.layout.list_image, null);
			holder = new ViewHolder();
			holder.imgProperty = (ImageView) vi.findViewById(R.id.imageView1);
			vi.setTag(holder);

		} else {
			holder = (ViewHolder) vi.getTag();
		}
		
		try {
			
			loader.DisplayImage(arrList.get(position), activity, holder.imgProperty,true);
			
			// Log.e(this.getClass().getName().toString(),
			// " NullPointerException : " + e.getMessage());
		} catch (Exception ex) {
			// Log.e("Exception @" + CustomAdapterDrumbi.class,
			// ex.getMessage());
		}

		return vi;
	}

}
